#ifndef MYTEST_LOG_H
#define MYTEST_LOG_H

#include "mytest_api.h"

#define __FILENAME__ (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILE__)
#define LOG_ERROR(args,...) _HMI_LOG(LOG_LEVEL_ERROR, __FILENAME__, __FUNCTION__, __LINE__, args, ##__VA_ARGS__)
#define LOG_DEBUG(args,...) _HMI_LOG(LOG_LEVEL_DEBUG, __FILENAME__, __FUNCTION__, __LINE__, args, ##__VA_ARGS__)

static char ERROR_FLAG[6][20] = {"NONE", "ERROR", "WARNING", "NOTICE", "INFO", "DEBUG"};

static void _HMI_LOG(enum LOG_LEVEL level, const char* file, const char* func, const int line, const char* log, ...)
{
    va_list args;
    va_start(args, log);

    char *message;
    if (log == NULL || vasprintf(&message, log, args) < 0) {
        message = NULL;
    }

    fprintf(stderr,  "[%s][%s][%s][%s():%d] >>> %s\n", getLocTime().c_str(), ERROR_FLAG[level], file, func, line, message);

    va_end(args);
    free(message);
}

#endif // MYTEST_LOG_H
